<div id="organization-permissions" data-name="organization-permissions" class="settings-section">
    <form class="admin-realm-form org-permissions-form">

        <div id="org-join-settings" class="settings-subsection-parent">
            <div class="subsection-header">
                <h3>
                    {{t "Joining the organization" }}
                    <i class="fa fa-info-circle settings-info-icon tippy-zulip-tooltip" aria-hidden="true" data-tippy-content="{{t 'Only owners can change these settings.' }}"></i>
                </h3>
                {{> settings_save_discard_widget section_name="join-settings" }}
            </div>
            <div class="m-10 inline-block organization-permissions-parent">
                <div class="input-group">
                    {{> settings_checkbox
                      setting_name="realm_invite_required"
                      prefix="id_"
                      is_checked=realm_invite_required
                      label=admin_settings_label.realm_invite_required}}
                    <label for="realm_invite_to_realm_policy" class="settings-field-label">{{t "Who can send email invitations to new users" }}
                    </label>
                    <select name="realm_invite_to_realm_policy" id="id_realm_invite_to_realm_policy" class="prop-element settings_select bootstrap-focus-style" data-setting-widget-type="number">
                        {{> dropdown_options_widget option_values=invite_to_realm_policy_values}}
                    </select>
                </div>

                {{> ../dropdown_widget_with_label
                  widget_name="realm_create_multiuse_invite_group"
                  label=(t 'Who can create reusable invitation links')
                  value_type="number"}}

                <div class="input-group">
                    <label for="realm_org_join_restrictions" class="settings-field-label">{{t "Restrict email domains of new users?" }}</label>
                    <select name="realm_org_join_restrictions" id="id_realm_org_join_restrictions" class="prop-element settings_select bootstrap-focus-style" data-setting-widget-type="string">
                        <option value="no_restriction">{{t "No restrictions" }}</option>
                        <option value="no_disposable_email">{{t "Don’t allow disposable email addresses" }}</option>
                        <option value="only_selected_domain">{{t "Restrict to a list of domains" }}</option>
                    </select>
                    <div class="dependent-settings-block">
                        <p id="allowed_domains_label" class="inline-block"></p>
                        {{#if is_owner }}
                        <a id="show_realm_domains_modal" role="button">{{t "[Configure]" }}</a>
                        {{/if}}
                    </div>
                </div>
                <div class="input-group time-limit-setting">
                    <label for="realm_waiting_period_threshold" class="settings-field-label">
                        {{t "Waiting period before new members turn into full members" }}
                        {{> ../help_link_widget link="/help/restrict-permissions-of-new-members" }}
                    </label>
                    <select name="realm_waiting_period_threshold" id="id_realm_waiting_period_threshold" class="prop-element settings_select bootstrap-focus-style" data-setting-widget-type="time-limit">
                        {{> dropdown_options_widget option_values=waiting_period_threshold_dropdown_values}}
                    </select>
                    {{!-- This setting is hidden unless `custom_period` --}}
                    <div class="dependent-settings-block">
                        <label for="id_realm_waiting_period_threshold_custom_input" class="inline-block">{{t "Waiting period (days)" }}:</label>
                        <input type="text" id="id_realm_waiting_period_threshold_custom_input"
                          name="realm_waiting_period_threshold_custom_input"
                          class="time-limit-custom-input"
                          value="{{ realm_waiting_period_threshold }}"/>
                    </div>
                </div>
            </div>
        </div>

        <div id="org-stream-permissions" class="settings-subsection-parent">
            <div class="subsection-header">
                <h3>{{t "Channel permissions" }}</h3>
                {{> settings_save_discard_widget section_name="stream-permissions" }}
            </div>
            <div class="m-10 inline-block organization-permissions-parent">
                {{> ../dropdown_widget_with_label
                  widget_name="realm_can_create_public_channel_group"
                  label=(t 'Who can create public channels')
                  value_type="number"}}

                {{> upgrade_tip_widget }}
                {{> settings_checkbox
                  setting_name="realm_enable_spectator_access"
                  prefix="id_"
                  is_checked=realm_enable_spectator_access
                  label=admin_settings_label.realm_enable_spectator_access
                  is_disabled=disable_enable_spectator_access_setting
                  help_link="/help/public-access-option"}}

                {{> ../dropdown_widget_with_label
                  widget_name="realm_can_create_web_public_channel_group"
                  label=(t 'Who can create web-public channels')
                  value_type="number"}}

                {{> ../dropdown_widget_with_label
                  widget_name="realm_can_create_private_channel_group"
                  label=(t 'Who can create private channels')
                  value_type="number"}}

                <div class="input-group">
                    <label for="realm_invite_to_stream_policy" class="settings-field-label">{{t "Who can add users to channels" }}</label>
                    <select name="realm_invite_to_stream_policy" id="id_realm_invite_to_stream_policy" class="prop-element settings_select bootstrap-focus-style" data-setting-widget-type="number">
                        {{> dropdown_options_widget option_values=common_policy_values}}
                    </select>
                </div>
                <div class="input-group">
                    <label for="realm_wildcard_mention_policy" class="settings-field-label">{{t "Who can notify a large number of users with a wildcard mention" }}
                        {{> ../help_link_widget link="/help/restrict-wildcard-mentions" }}
                    </label>
                    <select name="realm_wildcard_mention_policy" id="id_realm_wildcard_mention_policy" class="prop-element settings_select bootstrap-focus-style" data-setting-widget-type="number">
                        {{> dropdown_options_widget option_values=wildcard_mention_policy_values}}
                    </select>
                </div>
            </div>
        </div>

        <div id="org-direct-message-permissions" class="settings-subsection-parent">
            <div class="subsection-header">
                <h3>{{t "Direct message permissions" }}
                    {{> ../help_link_widget link="/help/restrict-direct-messages" }}
                </h3>
                {{> settings_save_discard_widget section_name="direct-message-permissions" }}
            </div>
            {{> ../dropdown_widget_with_label
              widget_name="realm_direct_message_permission_group"
              label=(t 'Who can authorize a direct message conversation')
              value_type="number" }}

            {{> ../dropdown_widget_with_label
              widget_name="realm_direct_message_initiator_group"
              label=(t 'Who can start a direct message conversation')
              value_type="number" }}
        </div>

        <div id="org-msg-editing" class="settings-subsection-parent">
            <div class="subsection-header">
                <h3>{{t "Message editing" }}
                    {{> ../help_link_widget link="/help/restrict-message-editing-and-deletion" }}
                </h3>
                {{> settings_save_discard_widget section_name="msg-editing" }}
            </div>
            <div class="inline-block organization-settings-parent">
                {{> settings_checkbox
                  setting_name="realm_allow_message_editing"
                  prefix="id_"
                  is_checked=realm_allow_message_editing
                  label=admin_settings_label.realm_allow_message_editing}}

                {{> settings_checkbox
                  setting_name="realm_allow_edit_history"
                  prefix="id_"
                  is_checked=realm_allow_edit_history
                  label=admin_settings_label.realm_allow_edit_history}}

                <div class="input-group time-limit-setting">
                    <label for="realm_message_content_edit_limit_seconds" class="settings-field-label">{{t "Time limit for editing messages" }}</label>
                    <select name="realm_message_content_edit_limit_seconds" id="id_realm_message_content_edit_limit_seconds" class="prop-element settings_select bootstrap-focus-style" {{#unless realm_allow_message_editing}}disabled{{/unless}} data-setting-widget-type="time-limit">
                        {{#each msg_edit_limit_dropdown_values}}
                            <option value="{{value}}">{{text}}</option>
                        {{/each}}
                    </select>
                    <div class="dependent-settings-block">
                        <label for="id_realm_message_content_edit_limit_minutes" class="inline-block realm-time-limit-label">
                            {{t 'Duration editing is allowed after posting (minutes)'}}:&nbsp;
                        </label>
                        <input type="text" id="id_realm_message_content_edit_limit_minutes"
                          name="realm_message_content_edit_limit_minutes"
                          class="time-limit-custom-input"
                          autocomplete="off"
                          value="{{ realm_message_content_edit_limit_minutes }}"
                          {{#unless realm_allow_message_editing}}disabled{{/unless}}/>
                    </div>
                </div>
            </div>
        </div>

        <div id="org-moving-msgs" class="settings-subsection-parent">
            <div class="subsection-header">
                <h3>{{t "Moving messages" }}
                    {{> ../help_link_widget link="/help/restrict-moving-messages" }}
                </h3>
                {{> settings_save_discard_widget section_name="moving-msgs" }}
            </div>
            <div class="input-group">
                <label for="realm_edit_topic_policy" class="settings-field-label">{{t "Who can move messages to another topic" }}</label>
                <select name="realm_edit_topic_policy" id="id_realm_edit_topic_policy" class="prop-element move-message-policy-setting settings_select bootstrap-focus-style" data-setting-widget-type="number">
                    {{> dropdown_options_widget option_values=edit_topic_policy_values}}
                </select>
            </div>

            <div class="input-group time-limit-setting">
                <label for="realm_move_messages_within_stream_limit_seconds" class="settings-field-label">{{t "Time limit for editing topics" }} <i>({{t "does not apply to moderators and administrators" }})</i></label>
                <select name="realm_move_messages_within_stream_limit_seconds" id="id_realm_move_messages_within_stream_limit_seconds" class="prop-element settings_select" data-setting-widget-type="time-limit">
                    {{#each msg_move_limit_dropdown_values}}
                        <option value="{{value}}">{{text}}</option>
                    {{/each}}
                </select>
                <div class="dependent-settings-block">
                    <label for="id_realm_move_messages_within_stream_limit_minutes" class="inline-block realm-time-limit-label">
                        {{t 'Duration editing is allowed after posting (minutes)'}}:&nbsp;
                    </label>
                    <input type="text" id="id_realm_move_messages_within_stream_limit_minutes"
                      name="realm_move_messages_within_stream_limit_minutes"
                      class="time-limit-custom-input"
                      autocomplete="off"/>
                </div>
            </div>

            <div class="input-group">
                <label for="realm_move_messages_between_streams_policy" class="settings-field-label">{{t "Who can move messages to another channel" }}
                </label>
                <select name="realm_move_messages_between_streams_policy" class="setting-widget prop-element bootstrap-focus-style move-message-policy-setting settings_select" id="id_realm_move_messages_between_streams_policy" data-setting-widget-type="number">
                    {{> dropdown_options_widget option_values=move_messages_between_streams_policy_values}}
                </select>
            </div>

            <div class="input-group time-limit-setting">
                <label for="realm_move_messages_between_streams_limit_seconds" class="settings-field-label">{{t "Time limit for moving messages between channels" }} <i>({{t "does not apply to moderators and administrators" }})</i></label>
                <select name="realm_move_messages_between_streams_limit_seconds" id="id_realm_move_messages_between_streams_limit_seconds" class="prop-element bootstrap-focus-style settings_select" data-setting-widget-type="time-limit">
                    {{#each msg_move_limit_dropdown_values}}
                        <option value="{{value}}">{{text}}</option>
                    {{/each}}
                </select>
                <div class="dependent-settings-block">
                    <label for="id_realm_move_messages_between_streams_limit_minutes" class="inline-block realm-time-limit-label">
                        {{t 'Duration editing is allowed after posting (minutes)'}}:&nbsp;
                    </label>
                    <input type="text" id="id_realm_move_messages_between_streams_limit_minutes"
                      name="realm_move_messages_between_streams_limit_minutes"
                      class="time-limit-custom-input"
                      autocomplete="off"/>
                </div>
            </div>
        </div>

        <div id="org-msg-deletion" class="settings-subsection-parent">
            <div class="subsection-header">
                <h3>{{t "Message deletion" }}
                    {{> ../help_link_widget link="/help/delete-a-message" }}
                </h3>
                {{> settings_save_discard_widget section_name="msg-deletion" }}
            </div>
            <div class="inline-block organization-settings-parent">
                <label for="org-msg-deletion" class="inline-block">
                    {{t "Administrators can delete any message." }}
                </label>
                <div class="input-group">
                    <label for="realm_delete_own_message_policy" class="settings-field-label">
                        {{t "Who can delete their own messages" }}
                    </label>
                    <select name="realm_delete_own_message_policy" id="id_realm_delete_own_message_policy" class="prop-element bootstrap-focus-style settings_select" data-setting-widget-type="number">
                        {{> dropdown_options_widget option_values=common_message_policy_values}}
                    </select>
                </div>

                <div class="input-group time-limit-setting">
                    <label for="realm_message_content_delete_limit_seconds" class="settings-field-label">
                        {{t "Time limit for deleting messages" }} <i>({{t "does not apply to administrators" }})</i>
                    </label>
                    <select name="realm_message_content_delete_limit_seconds" id="id_realm_message_content_delete_limit_seconds" class="prop-element bootstrap-focus-style settings_select" data-setting-widget-type="time-limit">
                        {{#each msg_delete_limit_dropdown_values}}
                            <option value="{{value}}">{{text}}</option>
                        {{/each}}
                    </select>
                    <div class="dependent-settings-block">
                        <label for="id_realm_message_content_delete_limit_minutes" class="inline-block realm-time-limit-label">
                            {{t "Duration deletion is allowed after posting (minutes)" }}:
                        </label>
                        <input type="text" id="id_realm_message_content_delete_limit_minutes"
                          name="realm_message_content_delete_limit_minutes"
                          class="time-limit-custom-input"
                          autocomplete="off"
                          value="{{ realm_message_content_delete_limit_minutes }}"/>
                    </div>
                </div>
            </div>
        </div>

        <div id="org-user-identity" class="settings-subsection-parent">
            <div class="subsection-header">
                <h3>{{t "User identity" }}
                    {{> ../help_link_widget link="/help/restrict-name-and-email-changes" }}
                </h3>
                {{> settings_save_discard_widget section_name="user-identity" }}
            </div>
            <div class="inline-block organization-permissions-parent">
                {{> settings_checkbox
                  setting_name="realm_require_unique_names"
                  prefix="id_"
                  is_checked=realm_require_unique_names
                  label=admin_settings_label.realm_require_unique_names}}

                {{> settings_checkbox
                  setting_name="realm_name_changes_disabled"
                  prefix="id_"
                  is_checked=realm_name_changes_disabled
                  label=admin_settings_label.realm_name_changes_disabled}}

                {{> settings_checkbox
                  setting_name="realm_email_changes_disabled"
                  prefix="id_"
                  is_checked=realm_email_changes_disabled
                  label=admin_settings_label.realm_email_changes_disabled}}

                {{> settings_checkbox
                  setting_name="realm_avatar_changes_disabled"
                  prefix="id_"
                  is_checked=realm_avatar_changes_disabled
                  label=admin_settings_label.realm_avatar_changes_disabled}}

            </div>
        </div>

        <div id="org-guest-settings" class="settings-subsection-parent">
            <div class="subsection-header">
                <h3>{{t "Guests" }}</h3>
                {{> settings_save_discard_widget section_name="guest-settings" }}
            </div>

            <div class="inline-block organization-permissions-parent">
                {{> settings_checkbox
                  setting_name="realm_enable_guest_user_indicator"
                  prefix="id_"
                  is_checked=realm_enable_guest_user_indicator
                  label=admin_settings_label.realm_enable_guest_user_indicator}}

                {{> ../dropdown_widget_with_label
                  widget_name="realm_can_access_all_users_group"
                  label=(t 'Who can view all other users in the organization')
                  value_type="number"
                  help_link="/help/guest-users#configure-whether-guests-can-see-all-other-users"}}
            </div>
        </div>

        <div id="org-other-permissions" class="settings-subsection-parent">
            <div class="subsection-header">
                <h3>{{t "Other permissions" }}</h3>
                {{> settings_save_discard_widget section_name="other-permissions" }}
            </div>
            <div class="m-10 inline-block organization-permissions-parent">
                <div class="input-group">
                    <label for="realm_bot_creation_policy" class="settings-field-label">{{t "Who can add bots" }}</label>
                    <select name="realm_bot_creation_policy" class="setting-widget prop-element settings_select bootstrap-focus-style" id="id_realm_bot_creation_policy" data-setting-widget-type="number">
                        {{> dropdown_options_widget option_values=bot_creation_policy_values}}
                    </select>
                </div>

                <div class="input-group">
                    <label for="realm_user_group_edit_policy" class="settings-field-label">{{t "Who can create and manage user groups" }}</label>
                    <select name="realm_user_group_edit_policy" id="id_realm_user_group_edit_policy" class="prop-element settings_select bootstrap-focus-style" data-setting-widget-type="number">
                        {{> dropdown_options_widget option_values=common_policy_values}}
                    </select>
                </div>

                <div class="input-group">
                    <label for="realm_add_custom_emoji_policy" class="settings-field-label">{{t "Who can add custom emoji" }}</label>
                    <select name="realm_add_custom_emoji_policy" class="setting-widget prop-element settings_select bootstrap-focus-style" id="id_realm_add_custom_emoji_policy" data-setting-widget-type="number">
                        {{> dropdown_options_widget option_values=common_policy_values}}
                    </select>
                </div>
            </div>
        </div>
    </form>
</div>
